<?php

use backend\assets\PrintAsset;
PrintAsset::register($this);
use yii\helpers\Html;
use backend\modules\statistics\assets\EchartsAsset;
EchartsAsset::register($this);
$this->title = '仔猪增长异常统计';
?>

<style>
    .table>tbody> tr >td{
        height: 70px;
        line-height: 70px;
    }
</style>


<section class="wrapper site-min-height">
    <!-- page start-->
    <section class="panel">
        <header class="panel-heading">
            <?= Html::a('返回','javascript:history.back(-1)'); ?>  <?= Html::encode($this->title) ?>
        </header>
<div class="row">
    <div class="col-md-10 col-md-offset-1" style="margin-top: 70px">
        <button class="btn btn-primary btn-sm" style="margin-bottom: 10px" id="print">打印</button>
        <!--work progress start-->
        <section class="panel">
            <div class="panel-body progress-panel">
                <div class="task-progress">
                    <h1>仔猪增长异常统计,三次巡检增长小于10kg</h1>
                </div>
                <div class="task-option">
                </div>
            </div>
            <table class="table table-hover">
                <tbody>
                    <tr>
                        <th>
                            批次
                        </th>
                        <th>
                            生长异常数
                        </th>
                        <th>
                            正常生长数
                        </th>
                        <th>
                            总数
                        </th>
                        <th>
                            统计图
                        </th>
                    </tr>
                    <?php $show = [] ?>
                    <?php foreach ($pigs as $key => $row) { ?>
                        <?php
                            $ktotal = array_key_exists($key,$batchlist)?$batchlist[$key]['total']:0;
                            $diff = $ktotal-$row['num']; ?>
                        <?php $show[$key] = [['name'=>'生长异常','value'=>$row['num']],['name'=>'正产生长','value'=>$diff]] ?>
                        <tr>
                            <td>
                                <?= $key?$key:'未定义批数' ?>
                            </td>
                            <td>
                                <?= $row['num'] ?>头
                            </td>
                            <td>
                                <?= $diff ?>头
                            </td>
                            <td>
                                <?= $ktotal ?>头
                            </td>
                            <td>
                                <div id="batch<?=$key?>" style="height: 70px;width: 70px;"></div>
                            </td>
                        </tr>
                    <?php } ?>
                </tbody>
            </table>
        </section>
        <!--work progress end-->
    </div>
</div>

    </section>
</section>


<script>
    <?php $this->beginBlock('disease') ?>

    // 基于准备好的dom，初始化echarts实例
    <?php foreach ($pigs as $key => $row) {?>
    var option<?=$key?> = {
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            x: 'left',
            data:[]
        },
        series: [
            {
                name:'',
                type:'pie',
                radius: ['50%', '70%'],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        show: false,
                        position: 'center'
                    },
                    emphasis: {
                        show: true,
                        textStyle: {
                            fontSize: '12',
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                data:<?= json_encode($show[$key]) ?>
            }
        ]
    };

    var myChart<?=$key?> = echarts.init(document.getElementById('batch<?=$key?>'));
    myChart<?=$key?>.setOption(option<?=$key?>);
    <?php } ?>

    <?php $this->endBlock('disease') ?>
    <?php $this->registerJs($this->blocks['disease'],\yii\web\View::POS_END) ?>
</script>



<script>
    <?php $this->beginBlock('js_end') ?>

    $(function(){
        $("#print").printPreview({
            obj2print:'#main-content',
            width:'810'
        });
    });
    <?php $this->endBlock('jsend') ?>
    <?php $this->registerJs($this->blocks['js_end'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>

</script>

